package cn.jobstart.task;

import cn.jobstart.common.Const;
import cn.jobstart.common.redis.RedisUtil;
import cn.jobstart.model.CompanyJob;
import cn.jobstart.pubInter.AbstractTask;
import cn.jobstart.searchExt.CompanyJobSearchExt;
import cn.jobstart.searchExt.CompanySearchExt;
import cn.jobstart.service.ICompanyJobService;
import cn.jobstart.service.ICompanyService;
import cn.jobstart.vo.KeyValueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author sunke
 * @version 1.0
 * @Description 企业库报表
 * @date 2023-09-28 14:53
 */

@EnableScheduling
@Slf4j
@Component
public class CompanyTask extends AbstractTask {

    @Resource
    private ICompanyService companyService;

    @Resource
    private ICompanyJobService companyJobService;


    @Resource
    private RedisUtil redisUtil;


    @Scheduled(cron = "0 0 06 * * ?")
   // @Scheduled(cron = "0 0/1 * * * ?")
    @Override
    public void run() {

        try {
            redisUtil.lRemoveAll(Const.REDIDS_KEY_COMPANY);

            CompanySearchExt companySearch = CompanySearchExt.getInstance();
            companySearch.setCustomSql(" (c_del_flag is null or c_del_flag=0)");
            int companyCount = companyService.getListCount(companySearch);


            KeyValueVO valueVO = new KeyValueVO();
            valueVO.setKey("企业数量");
            valueVO.setValue(companyCount);

            redisUtil.lSet(Const.REDIDS_KEY_COMPANY, valueVO);

            CompanyJobSearchExt jobSearch = CompanyJobSearchExt.getInstance();
            int jobCount = companyJobService.getListCount(jobSearch);

            valueVO = new KeyValueVO();
            valueVO.setKey("职位数量");
            valueVO.setValue(jobCount);
            redisUtil.lSet(Const.REDIDS_KEY_COMPANY, valueVO);


            jobSearch.setFieldNotNull(CompanyJob.PHONE);
            jobCount = companyJobService.getListCount(jobSearch);
            valueVO = new KeyValueVO();
            valueVO.setKey("含联系方式数量");
            valueVO.setValue(jobCount);
            redisUtil.lSet(Const.REDIDS_KEY_COMPANY, valueVO);


        } catch (Exception e) {

        }


    }
}
